package com.cn.crmsystem.service.businessService.Impl;

import com.cn.crmsystem.mapper.businessMapper.ProductMapper;
import com.cn.crmsystem.pojo.Order;
import com.cn.crmsystem.pojo.Product;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.ProblemService;
import com.cn.crmsystem.service.businessService.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public ResultJson selectProductAll(Map map) {
        List selectProductAll = productMapper.selectProductAll(map);
        ResultJson resultJson = new ResultJson();
        if (selectProductAll != null) {
            resultJson.getSuccess("成功",selectProductAll);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;

    }

    @Override
    public ResultJson selectByIdProduct(Integer id) {
        List selectByIdProduct = productMapper.selectByIdProduct(id);
        ResultJson resultJson = new ResultJson();
        if (selectByIdProduct !=null){
            resultJson.getSuccess("成功",selectByIdProduct);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson addProduct(Product product) {

        int addProduct = productMapper.addProduct(product);
        ResultJson resultJson = new ResultJson();
        if (addProduct > 0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson updateByIdProduct(Integer id) {
        int updateByIdProduct = productMapper.updateByIdProduct(id);
        ResultJson resultJson = new ResultJson();
        if (updateByIdProduct >0) {
            resultJson.getSuccess("成功",updateByIdProduct);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return  resultJson;

    }

    @Override
    public ResultJson deleteByIdProduct(Integer id) {
        int deleteByIdProduct = productMapper.deleteByIdProduct(id);
        ResultJson resultJson = new ResultJson();
        if (deleteByIdProduct>0){
            resultJson.getSuccess("成功",deleteByIdProduct);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }
}
